<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>设备监控管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		function cheackAll(obj){
			var isCheck = $(obj).is(":checked");

			$("#contentTable").find("input[type='checkbox']").each(function(){
				$(this).prop("checked", isCheck);
			});
		}
		function saveSettings(){
			var paramList = new Array();
			$("#contentTable").find("input[type='checkbox']").each(function () {
				if ($(this).prop('checked')) {
					var paramId = $(this).attr("id");
					var paramName = $("#paramName_"+paramId).val();
					var paramValue = $("#paramValue_"+paramId).val();
					var paramReceivers = $('#paramReceivers_'+paramId+' option:selected') .val();;
					var param = {};
					param.id = paramId;
					param.name = paramName;
					param.value = paramValue;
					param.reveiver = paramReceivers;
					paramList.push(param);
				}
			});
			console.log(paramList);
			if(paramList.length == 0){
				alertx("请选择要保存的设备监控参数");
            	return;
			}
			console.log(JSON.stringify(paramList));
			 $.ajax({
	                type: "post",
	                url: "${ctx}/equipment/eleMonitorParam/save",
	                data: {
	                    paramList: JSON.stringify(paramList)},
	                dataType: "JSON",
	                success: function(result) {
	                    if('0001' == result.code){
	                       // window.location.href="${ctx}/templet/eleTemplet/show?id=" + result.data;
	                    	alertx("保存成功!!!");
	                    }else{
	                    	alertx(result.msg);
	                    }
	                }
	            });
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/equipment/eleMonitorParam/"><spring:message code="monitor.params"/></a></li>
	</ul>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th style="width:40px;text-align:center;"><input type="checkbox" onclick="cheackAll(this)"/></th>
				<th></th>
				<th><spring:message code="monitor.param.name"/></th>
				<th><spring:message code="monitor.param.threshold"/></th>
				<th><spring:message code="monitor.param.recerver.type"/></th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${paramsList}" var="eleMonitorParam">
			<tr>
				 <td style="text-align:center;">
				 <c:if test="${eleMonitorParam.isUsed == '1' }">
				 	<input type="checkbox" id="${eleMonitorParam.id}"/>
				 </c:if>
				 <c:if test="${eleMonitorParam.isUsed == '0' }">
				 	<input type="checkbox" id="${eleMonitorParam.id}" checked/>			 
				 </c:if>
				<td>
					${eleMonitorParam.title}
				</td>
				<td>
					<input value="${eleMonitorParam.name}" id="paramName_${eleMonitorParam.id}"/>
				</td>
				<td>
					<input value="${eleMonitorParam.threshold}" pattern="#,##.00" id="paramValue_${eleMonitorParam.id}"/>				
				</td>
				<td>
					<select id="paramReceivers_${eleMonitorParam.id}">
						<c:forEach items="${fns:getDictList('receiver_type')}" var="receivers">
						<c:choose>
							<c:when test="${eleMonitorParam.receiverType == receivers.value}">
								<option value="${receivers.value}" selected>${receivers.label}</option>
							</c:when>
							<c:otherwise>
								<option value="${receivers.value}">${receivers.label}</option>
							</c:otherwise>
						</c:choose>
						</c:forEach>
					</select>
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="form-actions">
		<shiro:hasPermission name="equipment:eleMonitorParam:edit"><input id="saveSetting" class="btn" type="button" value="保   存" onclick="saveSettings();"/></shiro:hasPermission>
	</div>
</body>
</html>